# coding=utf-8

from framework.db.mysql import BaseDb
from tornado import gen
from lib import log
import md5


class Auth(BaseDb):

    @gen.coroutine
    def login_student(self, username, passwd, Fschool_id):
        qurey = '''SELECT a.Fid, a.Fuser_name, a.Ftype, a.Fpwd, 
                b.Fid student_id, b.Favatar, b.Fmajor_id, b.Fage
                , b.Ftel, b.Froom, b.Fdorm_id, b.Fno, b.Fname 
                FROM tb_user_login a 
                LEFT JOIN tb_student b 
                ON b.Fid = a.Fuser_id 
                AND b.Fschool_id = %s
                WHERE a.Fuser_name = %s 
                AND a.Fpwd = %s 
                AND a.Ftype = 1
                AND a.Fschool_id = %s 
                LIMIT 1'''
        passwd = md5.md5(passwd).hexdigest()
        ret = yield self.executejson(qurey, (Fschool_id, username, passwd, Fschool_id))
        raise gen.Return(ret)
